#!/usr/bin/python
# -*- coding: latin1 -*-
#
# @author herberthudson@gmail.com
# @version 1.0 - 6 Março de 2013
# @license Apache 2

import os, sys

def main(argv):

	arg = str(sys.argv[1])
	try:
		player = getPlayer()
		if (player != 0):
			option = getOption(str(arg))
			msg = setCommand(player,option)
			print msg
		else:
			if(arg == 'time' or arg == 'length'):
				print '0:00'
			else:
				print '--'
	except:
		print ' -- '
	
def getPlayer():
		players = ['conkyExaile','conkyRhythmbox','conkyBanshee','conkyClementine']
		
		for player in players:
			command = player + " --datatype=ST"
			temp = os.popen(command)
			value = temp.read()
			temp.close()
			value = value.replace('\n','')
			if value == 'Playing':
				return player
		
		return 0
	
def setCommand(player, option):
	command= player + " --datatype=" + option 
	temp=os.popen(command)
	value=temp.read()
	temp.close()
	return value.replace('\n','')
		
def getOption(option):
	values = {
		'status' : 'ST',
		'coverart' : 'CA',
		'title' : 'TI',
		'album' : 'AL',
		'artist' : 'AR',
		'genre' : 'GE',
		'year' : 'YR',
		'track' : 'TN',
		'filename' : 'FN',
		'bitrate' : 'BR',
		'length' : 'LE',
		'percent' : 'PP',
		'time' : 'PT',
		'volume' : 'VO',
		'rating' : 'RT'		
	}
	return values[option]

if __name__ == "__main__":
  	main(sys.argv)
